const app = getApp()
Page({
  data: {
    WrongQuestion: [],
    WrongAnswer: [],
    WrongChoose:[],
    Correct:[],
    question:"",
    index: 0,
    temp:[],
    qhaveImage: null,　//题目是否有图
    chaveImage:[],　　　　//选项是否含图
    corImage: false,　　//正确答案是否是图
    choImage: false　　//错选答案是否是图
  },

　　//加载错题数据
  onLoad: function () {
    this.setData({
      WrongQuestion: app.globalData.WrongQuestion,
      WrongAnswer: app.globalData.WrongAnswer,
      WrongChoose:app.globalData.WrongChoose,
      Correct: app.globalData.Correct
    })
    
  },

  //下一题
  changeData: function () {
    if(this.data.index < this.data.WrongQuestion.length - 1){
    this.data.index = this.data.index + 1
    this.setData({
      index: this.data.index
    })
    }
    else{
      wx.showToast({
        title: '已将错题展示完',
        icon: 'success',
        duration: 2000
      })
    }
    this.Start()
  },
  
　　//初始化数据
  Start: function () {
    this.data.chaveImage = []
    this.data.question = this.data.WrongQuestion[this.data.index]['content']
    this.data.qhaveImage = (this.data.WrongQuestion[this.data.index]['q_src1'] != '' || this.data.WrongQuestion[this.data.index]['q_src2'] != '' )
    for(let i = 0;i<this.data.WrongAnswer[this.data.index].length;i++){
      this.data.chaveImage.push(this.data.WrongAnswer[this.data.index][i].indexOf('http')>=0)
    }

    this.data.corImage = this.data.WrongChoose[this.data.index].indexOf('http')>=0
    this.data.choImage = this.data.Correct[this.data.index].indexOf('http')>=0

    this.setData({
      question: this.data.question,
      temp: this.data.WrongAnswer[this.data.index],
      qhaveImage: this.data.qhaveImage,
      chaveImage: this.data.chaveImage,
      corImage: this.data.corImage,
      choImage: this.data.choImage
    })
  },

//返回首页
reback:function(){
  app.globalData.WrongQuestion = []
  app.globalData.WrongAnswer = []
  app.globalData.WrongChoose = []
  app.globalData.Correct = []
  wx.redirectTo({
    url: '/pages/index/index',
  })
},

//界面显示
onShow:function(){
  this.Start()
},

})
